package org.ztr.yanai.blog.validator;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.ztr.yanai.blog.annotation.Phone;
import org.ztr.yanai.blog.utils.ValidationUtil;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/11/22 14:30
 * @Description: 手机号校验器
 * @Version: 1.0
 */
public class PhoneValidator implements ConstraintValidator<Phone, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        // 允许为空，由@NotBlank等注解控制是否必填
        if (value == null || value.trim().isEmpty()) {
            return true;
        }
        return ValidationUtil.isValidPhone(value);
    }
}
